package plugins

import "github.com/gin-gonic/gin"

type IResponse interface {
	Json(ctx *gin.Context, httpCode int, result bool, data interface{}, message string, trace interface{})
	Fill(result bool, data interface{}, message string, trace interface{}) *Response
}

type Response struct {
	Result  bool        `json:"result"`
	Data    interface{} `json:"data"`
	Message string      `json:"message"`
	Trace   interface{} `json:"trace"`
}

var response *Response

func init() {
	response = &Response{}
}

func (r *Response) Json(ctx *gin.Context, httpCode int, result bool, data interface{}, message string, trace interface{}) {
	ctx.JSON(httpCode, r.Fill(result, data, message, trace))
}

func (r *Response) Fill(result bool, data interface{}, message string, trace interface{}) *Response {
	r.Result = result
	r.Data = data
	r.Message = message
	r.Trace = trace
	return r
}

func NewResponse() *Response {
	return response.Fill(false, nil, "", nil)
}
